package com.gg.user.gguser.controller;


import com.gg.user.gguser.service.GgUserRoleService;
import com.gg.vo.return_format;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 杨鑫磊
 * @date 2020-03-23
 */
@RestController
@RequestMapping("/userRole")
public class GgUserRoleController {

    @Autowired
    private GgUserRoleService ggUserRoleService;


    /**
     * 修改外部用户身份
     * upUserId  用户等级
     * grade  要修改用户的等级id 1超管不能不能增加也不能删除，2内部员工，3外部公司，4外部公司对应的员工，5游客默认进来就是游客
     */
    @GetMapping("/updateUserRole")
    public Object updateUserRole(HttpServletResponse response, HttpServletRequest request, String upUserId, Integer grade) throws Exception{
        return ggUserRoleService.updateUserRole(response, request, upUserId, grade);
    }

    /**
     * 外部用户绑定对应公司账号
     *
     * upUserId 公司账号的id也就是公司超级管理员
     * npUserId 需要绑定的用户
     */
    @GetMapping("/bindingUser")
    public Object bindingUser(HttpServletResponse response, HttpServletRequest request, String upUserId, String npUserId) throws Exception{
        return ggUserRoleService.bindingUser(response, request, upUserId, npUserId);
    }





    /**
     *  增加 角色
     */
    @GetMapping("/addRole")
    public Object addRole(HttpServletResponse response, HttpServletRequest request, String name,String grade) throws Exception {
        return ggUserRoleService.addRole(response, request, name, grade);
    }

    /**
     * 增加用户角色
     * userid  用户id
     *  roleid 角色id
     */
    @GetMapping("addUserRole")
    public Object addUserRole(HttpServletResponse response, HttpServletRequest request, String userid,Integer roleid) throws Exception {
        return ggUserRoleService.addUserRole(response, request, userid, roleid);
    }

    /**
     *  增加角色组
     */
    @GetMapping("/groduUserGropu")
    public Object groduUserGropu(HttpServletResponse response, HttpServletRequest request, String name, String grade) throws Exception {
        return ggUserRoleService.groduUserGropu(response, request, name, grade);
    }

    /**
     * 增加角色组和用户之间关系
     */
    @GetMapping("/groduUserRoleGropu")
    public Object groduUserRoleGropu(HttpServletResponse response, HttpServletRequest request, String userid, Integer roleidGroup) throws Exception {
        return ggUserRoleService.groduUserRoleGropu(response, request, userid, roleidGroup);
    }

    /**
     * 增加用户或者用户组权限都有那些权限
     */
    @GetMapping("/addUserRoleAll")
    public Object addUserRoleAll(HttpServletResponse response, HttpServletRequest request, String userid,String menu, Integer role, Integer type) throws Exception {
        return ggUserRoleService.addUserRoleAll(response, request, userid, menu, role, type);
    }


}
